var ckbj = document.getElementById("ckbj");
var ckll = document.getElementById("ckll");
var ckqs = document.getElementById("ckqs");
var calc = document.getElementById("calc");
var result = document.getElementsByTagName("footer")[0];

//文件改变后，光标离开输入框时执行
/*
ckbj.onchange = ckll.onchange = ckqs.onchange = function () {
    var currentValue = parseInt(this.value);
    if (isNaN(currentValue)) {
        alert("您输入的不是数字！")
        this.value = "";
    }
}*/

function checkInput() {
    var currentValue = parseFloat(this.value);
    if (isNaN(currentValue)) {
        alert("您输入的不是数字！")
        this.value = "";
    }
}

ckbj.onchange = ckll.onchange = ckqs.onchange = checkInput;

calc.onclick = function () {
    if (isNaN(parseFloat(ckbj.value)) || isNaN(parseFloat(ckll.value)) || isNaN(parseInt(ckqs.value))) {
        alert("您输入的格式不正确！")
        return false;
    }

    var ll = parseFloat(ckbj.value) * parseFloat(ckll.value) * parseInt(ckqs.value) / 100;

    result.innerHTML = "本息合计：" + (ll + parseFloat(ckbj.value)).toFixed(2);

    //计算完成后清空
    ckbj.value = "";
    ckll.value = "";
    ckqs.value = "";

    result.style.display = "block";
    return false;
}
